<?php namespace App\Core\Metadata\Data;

use Auth, Request;

class EnvData extends BaseData{

    public function __construct($data) {
        $this->data = $data;
        $this->matchData();
    }
    
    private function matchData(){
        foreach($this->data as $key => $val){
            if(!method_exists($this, 'env'.ucfirst($val))){
                throw new \Exception('parameter not validated');
            }
            $this->data[$key] = $this->{'env'.ucfirst($val)}();
        }
    }
    
    //当前登录用户ID
    public function envCurrentUserId(){
        $loginUser = Auth::user();
        return $loginUser->user_id;
    }
    
    //当前时间
    public function envCurrentTime(){
        return time();
    }
    
    //当前用户IP地址
    public function envCurrentClientIp(){
        Request::getClientIp();
    }
}